package com.ruoyi.common.model.vo;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.Collection;

/**
 * 分页参数
 *
 * @author ruoyi
 * @date 2024-11-18
 */
public class BasePage<T> {

    /**
     * 当前页
     */
    private final int page;

    /**
     * 每页条数
     */
    private final int size;
    /**
     * 总数
     */
    private final int total;
    /**
     * 总页数
     */
    private final int pages;
    /**
     * 列表数据
     */
    private final Collection<T> items;

    public BasePage(int page, int size, int total, Collection<T> items) {
        this.page = page;
        this.size = size;
        this.total = total;
        this.items = items;
        this.pages = size == 0 ? 0 : total / size + (total % size == 0 ? 0 : 1);
    }

    public BasePage(int page, int size, int total, int pages, Collection<T> items) {
        this.page = page;
        this.size = size;
        this.total = total;
        this.items = items;
        this.pages = pages;
    }

    public BasePage(Page<T> pageData) {
        this((int) pageData.getCurrent(), (int) pageData.getSize(), (int) pageData.getTotal(), (int) pageData.getPages(), pageData.getRecords());
    }

    public int getPage() {
        return page;
    }

    public int getSize() {
        return size;
    }

    public int getTotal() {
        return total;
    }

    public int getPages() {
        return pages;
    }

    public Collection<T> getItems() {
        return items;
    }
}
